
import React, { Component } from 'react'

import { Route, Switch, Redirect } from 'react-router-dom'

import Index from './views/News'
import News from './views/News/News'
import Notfound from './views/Notfound';

class App2 extends Component {
  render() {
    return (
      <div>
        {/* 
          匹配的规则是从上向下，一直匹配下去 
          Switch组件解决，一直向下匹配的问题，只要有一个符合路由规则就停止匹配了
          Route中一个属性，严格匹配 exact
        */}
        <Switch>
          <Route exact path="/news" component={Index} />
          <Route path="/news/:id?" component={News} />
          {/* 重定向 from来源 to跳转到的页面 */}
          <Redirect exact from="/" to="/news" />
          {/* 404页面 Route组件没有path表示匹配所有 相等于 path="*" */}
          <Route component={Notfound} />
        </Switch>
      </div>
    );
  }
}

export default App2;
